
* data
use "data/inputs/MunicipioData_AD_Chavez.dta", clear

* save correlation with density
mat results = J(11, 2, 0)
local i = 1
foreach year of numlist 1963(5)1998 2000(6)2012 {
	cap cor ln_density`year' share_presAD`year'
	if _rc == 0 {
	mat results[`i',1] = `year'
	mat results[`i',2] = `r(rho)'
	}
	else {
	cor ln_density`year' share_presOFIC`year'
	mat results[`i',1] = `year'
	mat results[`i',2] = `r(rho)'
	}
	local i = `i' + 1
}

* use results
clear 
svmat results
rename results1 year
rename results2 cor_density



* density graph for paper
#delimit;

twoway (connected cor_density year if year >= 1958, 
	    lcolor(white) mcolor(white) 
	    mlwidth(thick) mlcolor(white) msize(large))
		
	   (connected cor_density year if year >= 1958 & year <= 2012, 
	    lcolor(black) mcolor(black) lwidth(medthick)
	    mlwidth(thick) mlcolor(white) msize(large))
		
	   (scatter cor_density year if year == 1958, 
	    mcolor(black) 
	    mlwidth(thick) mlcolor(white) msize(large))
		
	   (scatter cor_density year if year >= 1998 & year <= 2012, 
	    lcolor(black) mcolor(black) lwidth(medthick) msymbol(diamond)
	    mlwidth(thick) mlcolor(white) msize(large))
		
   	   (scatter cor_density year if year == 1998, 
	    lcolor(black) mcolor(blue) msymbol(diamond)
	    mlwidth(thick) mlcolor(white) msize(large)),

		yline(0, lwidth(thick) lcolor(gs12))
		graphregion(fcolor(white) lcolor(white) margin(zero))
        plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none))
        xsize(11) ysize(7.75)
		title("", size(large))
		ytitle("Correlation with Population Density", color(black) size(large))
		xtitle("")
        yscale()
		ylabel(-.6(.2).4, labsize(large) glcolor(white))
		xlabel(1958 "1958"
		1968 "1968"
		1978 "1978"
		1988 "1988"
		1998 "98  "
		2000 "  00"
		2006 "2006"
		2012 "2012", labsize(large))
		xscale( range(1958 2014))
        legend(order(3 "AD vs. Density" 4 "Chávez vs. Density") pos(8) ring(0) rows(2) region(lcolor(white)));
graph export "figures/FigureD1.pdf", replace;


* End
